#!/bin/sh
uname=meyersg@athena.ecs.csus.edu
subdir=nodirectory
lcldir=`echo ~/csc60`

err1() {
	echo " "
	echo "scp failed check password and make sure the directory"
	echo "    exsists on "${uname}"'s account"
	echo " "
	exit

}

err2() {
	echo " "
	echo "ERROR: Subdirectory ~/csc60/"${subdir}" does not exsist."
	echo "Re-run and use exsisting subdirectory of /home/nekorb/csc60/"
	echo " "		
	exit

}

if [ $# -ge 2 ]; then
	echo "Usage: "$0" [subdirectory]"
	echo " "
	echo "The path entered will be copied from local ~/csc60/[subdirectory] to"
	echo ${uname}"'s equivalent directory"
	echo " "	
	exit
fi

if [ ! $# -eq 0 ]; then
	subdir=$1
fi

if [ -e ${lcldir}/${subdir} ]; then
	#Subdirectory Exsists

	echo "Uploading directory via ssh to "${uname}"'s area"
	scp -r ${lcldir}/${subdir}/ ${uname}:~/csc60/
	if [ "$?" -ne 0 ]; then
		err1
	fi
	echo "Completed successfully"
	exit
else
	if [ ${subdir} != 'nodirectory' ]; then
		err2
	fi

	#Subdirectory Doesn't exsist
	echo "Enter a subdirectory of ~/csc60/ to upload."
	read my_path

	if [ ! -d ${lcldir}/$my_path ]; then
		subdir=${my_path}
		err2
	fi

	echo "Uploading directory via ssh to "${uname}"'s area"
	scp -r ${lcldir}/${my_path}/ ${uname}:~/csc60/
	if [ "$?" -ne 0 ]; then
		err1
	fi
	echo "Completed successfully"
	exit
fi

exit
